const CodeEnum = require('../../enum/code')
module.exports = class ResultModel {

	constructor({
		errCode = "",
		errMsg = "",
		data = ""
	} = {}) {
		this.errCode = errCode;
		this.errMsg = errMsg;
		this.data = data;
	}

	static success(data = "", msg = "") {
		const instance = this.instance();
		instance.errMsg = msg;
		instance.data = data;
		instance.errCode = CodeEnum.SUCCESS;
		return instance
	}
	static error(  msg = "" ,code = "") {
		const instance = this.instance();
		instance.errMsg = msg;
		instance.errCode = code;
		return instance;
	}
	static exception(data = "", msg = "") {
		const instance = this.instance();
		instance.errCode = CodeEnum.EXCEPTION;
		instance.errMsg = msg;
		instance.data = data;
		return instance;
	}
	static instance() {
		const bin = {};
		for (key in this) {
			bin[key] = this[key]
		}
		return bin;
	}
}
